package org.tigris.jasmincc.migration.implementation;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;

public class JasminCCMigrator {
	PrintStream printer = null;

	public void migrate(File file, String corpusName) {
		String line;

		int dot = file.getName().lastIndexOf('.');
		String grammarName = file.getName().substring(0, dot);
		String outputFileName = file.getName().substring(0, dot) + ".jcc";
		try {
			FileReader reader = new FileReader(file.getAbsoluteFile());
			BufferedReader breader = new BufferedReader(reader);
			printer = new PrintStream(outputFileName);

			printer.println("namespace " + corpusName + ";");
			printer.println("grammar " + grammarName + ":{}{");
			while ((line = breader.readLine()) != null) {
				printer.print("\t" + line);
			}
			printer.print("}");
			printer.close();
			breader.close();
			reader.close();
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}

}
